import 'package:floor/floor.dart';
import '../entities/user_entity.dart';

@dao
abstract class UserDao {
  // Future查询全部数据
  @Query('SELECT * FROM User')
  Future<List<User>> getAllUsers();

  // Stream观察数据库变化
  @Query('SELECT * FROM User')
  Stream<List<User>> watchAllUsers();

  // 根据ID查询单个用户
  @Query('SELECT * FROM User WHERE id = :id')
  Future<User?> getUserById(int id);

  // 根据部门查询用户
  @Query('SELECT * FROM User WHERE department = :department')
  Future<List<User>> getUsersByDepartment(String department);

  // 插入单个用户
  @insert
  Future<void> insertUser(User user);

  // 批量插入用户
  @insert
  Future<void> insertUsers(List<User> users);

  @update
  Future<void> updateUsers(List<User> users);

  // 更新用户
  @update
  Future<void> updateUser(User user);

  // 删除用户
  @delete
  Future<void> deleteUser(User user);

  // 根据ID删除用户
  @Query('DELETE FROM User WHERE id = :id')
  Future<void> deleteUserById(int id);

  // 清空所有用户
  @Query('DELETE FROM User')
  Future<void> deleteAllUsers();

  // 获取前三条用户
  @Query('SELECT * FROM User LIMIT 3')
  Future<List<User>> getTopThreeUsers();
}